package ai.people.netmon.signal.service.impl;

import ai.people.netmon.framework.domain.signal.entity.SignalUser;
import ai.people.netmon.framework.domain.signal.vo.SignalUserVO;
import ai.people.netmon.framework.exception.enums.CommonEnum;
import ai.people.netmon.framework.utils.AssertUtils;
import ai.people.netmon.signal.mapper.UserMapper;
import ai.people.netmon.signal.service.UserService;
import ai.people.netmon.utils.DesensitizationUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 用户服务impl
 *
 * @author yuanqinglong
 * @date 2022/4/25 15:58
 */
@Service
@RequiredArgsConstructor
public class UserServiceImpl implements UserService {


    /**
     * 用户映射器
     */
    private final UserMapper userMapper;

    /**
     * 获取用户通过用户名
     *
     * @param username 用户名
     * @return {@link SignalUser}
     */
    @Override
    public SignalUserVO getUserByUsername(String username) {
        LambdaQueryWrapper<SignalUser> lambdaQuery = Wrappers.lambdaQuery(SignalUser.class);
        lambdaQuery.eq(SignalUser::getUserName,username);
        SignalUser signalUser = userMapper.selectOne(lambdaQuery);
        AssertUtils.isNotNull(signalUser, CommonEnum.QUERY_NOT_FOUND);
        signalUser.setPhone(DesensitizationUtils.hiddenPhone(signalUser.getPhone()));
        return SignalUserVO.build(signalUser);
    }

}
